<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../js/vue.global.js"></script>
    <title></title>
</head>
<body>
    <div id="app">
        <input type="text" v-model="keyword"><button @click="select()">查询</button>
        <li v-for="(stu, index) in students" :key="stu.show">
            {{stu.id}} -- {{stu.name}} -- {{stu.age}}
        </li>
    </div>

    <script>
        const myApp = {
            data(){
                return {
                    students:[
                        {id:210001, name:"张三", age:18},
                        {id:210002, name:"李四", age:17},
                        {id:210003, name:"王五", age:28}
                    ],
                    keyword:"",
                    stuBackUp:[]
                }
            },
            methods: {
                select()
                {
                    if(this.keyword === "")
                    {
                        this.students = this.stuBackUp;
                        return;
                    }

                    this.stuBackUp = this.students;
                    this.students = []
                    this.students = this.stuBackUp.filter((stu) => stu.name.match(this.keyword));

                }
            },
        }

        Vue.createApp(myApp).mount("#app");
    </script>
</body>
</html>